

//
//  SuggestController.m
//  QuickCure37
//
//  Created by apple on 16/7/7.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "SuggestController.h"
@interface SuggestController()<UITextViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,weak)UITextView *textView;
@property(nonatomic,weak)UILabel *label;
@property(nonatomic,weak)UILabel *remindLabel;
@property(nonatomic,weak)UITableView *tableView;
@end
@implementation SuggestController


-(void)viewDidLoad{
    [super viewDidLoad];
    [self setupUI];
    [self setupTableView];
    self.automaticallyAdjustsScrollViewInsets = NO;
}

-(void)setupUI{
    //输入反馈部分
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 65, self.view.bounds.size.width,300)];
    [self.view addSubview:topView];
    
    
    
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(5, 5, self.view.bounds.size.width-10, 180)];
    
   
    
    self.textView = textView;
    textView.delegate = self;
    
   
    

    textView.backgroundColor = [UIColor colorWithRed:241/255.0 green:240/255.0 blue:247/255.0 alpha:1];
    if (kDevice_Is_iPhone5)
    {
        textView.font = [UIFont systemFontOfSize:15];
    }
    else if (kDevice_Is_iPhone6Plus)
    {
        textView.font = [UIFont systemFontOfSize:19];
    }
    else
    {
        textView.font = [UIFont systemFontOfSize:17];
    }
    
    
    [topView addSubview:textView];
    
    
    

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 100, 20)];
    label.text = @"请输入反馈信息";
    
    if (kDevice_Is_iPhone5)
    {
        label.font = [UIFont systemFontOfSize:15];
    }
    else if (kDevice_Is_iPhone6Plus)
    {
        label.font = [UIFont systemFontOfSize:19];
    }
    else
    {
        label.font = [UIFont systemFontOfSize:17];
    }
    [label sizeToFit];
    
    label.enabled = NO;
    label.textColor =[UIColor blueColor];
    label.backgroundColor = [UIColor clearColor];
    [topView addSubview:label];
    
    self.label = label;
    
    
    
    //提交反馈
    //UIButton *sendButton = [[UIButton alloc]initWithFrame:CGRectMake(300, 190, 60, 30)];
    UIButton *sendButton = [[UIButton alloc] init];
    
    sendButton.layer.cornerRadius = 5;
    sendButton.layer.masksToBounds = YES;
    
    [sendButton setTitle:@"提交反馈" forState:UIControlStateNormal];
    
    if (kDevice_Is_iPhone5)
    {
        sendButton.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (kDevice_Is_iPhone6Plus)
    {
         sendButton.titleLabel.font = [UIFont systemFontOfSize:19];
    }
    else
    {
         sendButton.titleLabel.font = [UIFont systemFontOfSize:17];
    }
    
    [sendButton sizeToFit];
    
    sendButton.backgroundColor = [UIColor colorWithRed:0/255.0 green:199/255.0 blue:212/255.0 alpha:1];
    [topView addSubview:sendButton];
    
    //设置sendButton的约束
    [sendButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(topView).offset(-5);
        make.top.equalTo(textView.bottom).offset(5);
    }];
    
    
    //提醒字数
    
   
    
    UILabel *remindLabel = [[UILabel alloc] init];
    
    
    self.remindLabel = remindLabel;
    
    remindLabel.text =@"您还可以输入的字数为:200";
    remindLabel.textAlignment = NSTextAlignmentCenter;
    
    if (kDevice_Is_iPhone5)
    {
        remindLabel.font = [UIFont systemFontOfSize:14];
    }
    else if (kDevice_Is_iPhone6Plus)
    {
        remindLabel.font = [UIFont systemFontOfSize:18];
    }
    else
    {
        remindLabel.font = [UIFont systemFontOfSize:16];
    }
    
    [remindLabel sizeToFit];
    
    [topView addSubview:remindLabel];
    
    //设置约束
    [remindLabel makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(sendButton);
        make.right.equalTo(sendButton.left).offset(-15);
        
    }];
    
    
    
    
    
    //联系方式
    UILabel *connectLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 300, self.view.bounds.size.width, 40)];
    //UILabel *connectLabel = [[UILabel alloc] init];
    
    
    connectLabel.backgroundColor = [UIColor colorWithRed:241/255.0 green:240/255.0 blue:247/255.0 alpha:1];
    connectLabel.text = @"    欢迎联系我们";
    
    if (kDevice_Is_iPhone5)
    {
        connectLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (kDevice_Is_iPhone6Plus)
    {
        connectLabel.font = [UIFont systemFontOfSize:19];
    }
    else
    {
        connectLabel.font = [UIFont systemFontOfSize:17];
    }
    
    
    [self.view addSubview:connectLabel];
    
    
    
    //tableview
}
//textView的代理方法
-(void)textViewDidChange:(UITextView *)textView
{
    //self.textView = textView;
    if (textView.text.length !=0)
    {
        self.label.text = @"";
    }
    if (textView.text.length ==0)
    {
        self.label.text = @"请输入反馈信息";
    }
    int labelText  = 200 - (int)textView.text.length;
    self.remindLabel.text = [NSString stringWithFormat:@"您还可以输入的字数为:%d",labelText];
    if (labelText ==0)
    {
        self.textView.userInteractionEnabled = NO;
    }
}


-(void)setupTableView
{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 340, self.view.bounds.size.width, 88)];
    
    
    tableView.contentSize = CGSizeMake(0, 0);
    tableView.bounces = NO;
    self.tableView =tableView;
    tableView.delegate =self;
    tableView.dataSource =self;
    [self.view addSubview:tableView];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"suggestCell"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"suggestCell" forIndexPath:indexPath];
    if (indexPath.row ==0) {
        cell.textLabel.text = @"客服电话 : 400 400 400";
        cell.imageView.image = [UIImage imageNamed:@"dianhua"];
        
    }
    if (indexPath.row ==1) {
        cell.textLabel.text = @"用户交流群 : QQ 123456";
        cell.imageView.image = [UIImage imageNamed:@"qq"];
    }
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.view endEditing:YES];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
    [self.textView resignFirstResponder];
}



@end
